package com.openbravo.data.gui;

import aaaCfg.IocX4casher;

import com.attilax.acc.AccService;
import com.attilax.user.AbsService;
import com.attilax.user.UserService;
import com.openbravo.basic.BasicException;
import com.openbravo.data.loader.LocalRes;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.user.BrowsableData;
import com.openbravo.data.user.BrowsableEditableData;
import com.openbravo.data.user.SaveProvider;
import com.openbravo.data.user.StateListener;

import java.awt.FlowLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.ListModel;

public class JSaver extends JPanel
  implements StateListener
{
  protected BrowsableEditableData m_bd;
  private JSeparator jSeparator1;
  private JButton jbtnDelete;
  private JButton jbtnNew;
  private JButton jbtnSave;

  public JSaver(BrowsableEditableData paramBrowsableEditableData)
  {
    initComponents();
    this.m_bd = paramBrowsableEditableData;
    this.m_bd.addStateListener(this);
  }

  public void updateState(int paramInt)
  {
    switch (paramInt)
    {
    case 3:
      this.jbtnNew.setEnabled(this.m_bd.canInsertData());
      this.jbtnDelete.setEnabled(false);
      this.jbtnSave.setEnabled(this.m_bd.canInsertData());
      break;
    case 2:
      this.jbtnNew.setEnabled(this.m_bd.canInsertData());
      this.jbtnDelete.setEnabled(false);
      this.jbtnSave.setEnabled(this.m_bd.canDeleteData());
      break;
    case 0:
      this.jbtnNew.setEnabled(this.m_bd.canInsertData());
      this.jbtnDelete.setEnabled(false);
      this.jbtnSave.setEnabled(false);
      break;
    case 1:
      this.jbtnNew.setEnabled(this.m_bd.canInsertData());
      this.jbtnDelete.setEnabled(this.m_bd.canDeleteData());
      this.jbtnSave.setEnabled(this.m_bd.canUpdateData());
    }
  }

  private void initComponents()
  {
    this.jbtnNew = new JButton();
    this.jbtnDelete = new JButton();
    this.jSeparator1 = new JSeparator();
    this.jbtnSave = new JButton();
    setLayout(new FlowLayout(0));
    this.jbtnNew.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/editnew.png")));
    this.jbtnNew.setFocusPainted(false);
    this.jbtnNew.setFocusable(false);
    this.jbtnNew.setMargin(new Insets(2, 8, 2, 8));
    this.jbtnNew.setRequestFocusEnabled(false);
    this.jbtnNew.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JSaver.this.jbtnNewActionPerformed(paramActionEvent);
      }
    });
    add(this.jbtnNew);
    this.jbtnDelete.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/editdelete.png")));
    this.jbtnDelete.setFocusPainted(false);
    this.jbtnDelete.setFocusable(false);
    this.jbtnDelete.setMargin(new Insets(2, 8, 2, 8));
    this.jbtnDelete.setRequestFocusEnabled(false);
    this.jbtnDelete.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JSaver.this.jbtnDeleteActionPerformed(paramActionEvent);
      }
    });
    add(this.jbtnDelete);
    add(this.jSeparator1);
    this.jbtnSave.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/filesave.png")));
    this.jbtnSave.setFocusPainted(false);
    this.jbtnSave.setFocusable(false);
    this.jbtnSave.setMargin(new Insets(2, 8, 2, 8));
    this.jbtnSave.setRequestFocusEnabled(false);
    this.jbtnSave.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JSaver.this.jbtnSaveActionPerformed(paramActionEvent);
      }
    });
    add(this.jbtnSave);
  }

  private void jbtnSaveActionPerformed(ActionEvent paramActionEvent)
  {
    try
    {
    	//com.openbravo.data.user.BrowsableEditableData@13bf30c
      this.m_bd.saveData();
      
      //create acc
      BrowsableData listModel = (BrowsableData) this.m_bd.getListModel();
      SaveProvider sp=listModel.getM_saveprov();
  //    TableDefinition td=sp.paramTableDefinitionQ11;
    if(  TableDefinition.tablenameQ1.get().equals("CUSTOMERS"))
    {
    	 Map m=new AbsService().Last_row("customers","curdate");
 //  String val= 	new AbsService().Last("customers", "ID");
    	//System.out.println();
    	
    	
    	  AccService accS=IocX4casher.getBean(AccService.class);
		   String usernameInAccSys = m.get("ID").toString()+"_"+ m.get("TAXID").toString()+"_"+ m.get("NAME").toString();
		accS.createAcc(usernameInAccSys,0);
    }
      
   
      
      
    }
    catch (BasicException localBasicException)
    {
      MessageInf localMessageInf = new MessageInf(-67108864, LocalRes.getIntString("message.nosave"), localBasicException);
      localMessageInf.show(this);
    }
  }

  private void jbtnDeleteActionPerformed(ActionEvent paramActionEvent)
  {
    try
    {
      this.m_bd.actionDelete();
    }
    catch (BasicException localBasicException)
    {
      MessageInf localMessageInf = new MessageInf(-67108864, LocalRes.getIntString("message.nodelete"), localBasicException);
      localMessageInf.show(this);
    }
  }

  private void jbtnNewActionPerformed(ActionEvent paramActionEvent)
  {
    try
    {
      this.m_bd.actionInsert();
    }
    catch (BasicException localBasicException)
    {
      MessageInf localMessageInf = new MessageInf(-67108864, LocalRes.getIntString("message.nonew"), localBasicException);
      localMessageInf.show(this);
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.data.gui.JSaver
 * JD-Core Version:    0.6.0
 */